﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using Hotnet.Biz.NSBizNews;
using Hotnet.Entity;
using Hotnet.Web.Utility;
using Hotnet.Biz.NSBizCommon;
using Hotnet.Entity.Enum;
using Hotnet.Entity.Search;

namespace Hotnet.Web.Controllers.Admin
{
	public class AdminNewsCategoryController : AdminBaseController
	{

		public static SelectList NewsNetList
		{
			get
			{
				BizSourceFrom s = new BizSourceFrom();
				List<SourceFrom> list = s.List(EnumSystemCategory.新闻).ToList();
				SourceFrom temp = new SourceFrom();
				temp.SourceFromID = -1;
				temp.Name = "全部";
				list.Insert(0, temp);
				return new SelectList(list, "SourceFromID", "Name");
			}
		}
		//
		// GET: /AdminNewsCategory/

		private BizNewsCategory _BizNewsCategory;
		private BizNewsCategory BizNewsCategory
		{
			get
			{
				if (_BizNewsCategory == null)
					_BizNewsCategory = new BizNewsCategory();
				return _BizNewsCategory;
			}
		}

		private BizNews _BizNews;
		private BizNews BizNews
		{
			get
			{
				if (_BizNews == null)
					_BizNews = new BizNews();
				return _BizNews;
			}
		}

		public ActionResult Index(int id , int? pageNo,SearchNewsCondition condition)
		{
			int totalCount;
			condition.CategoryID = id;
			var newses = BizNews.ListByCategoryId(condition, id, PAGE_SIZE, pageNo ?? 0, out totalCount, false, condition.IsPublished);
			var category = BizNewsCategory.Get(id);
			ViewData["Category"] = category;
			ViewData["CategoryID"] = id;
			ViewData["PaginateHelper"] = PaginateHelper.ConstructPaginate(totalCount, pageNo ?? 0, PAGE_SIZE, "/AdminNewsCategory/Index/" + id,condition);
			return View(newses);
		}

		public ActionResult List()
		{
			var categories = BizNewsCategory.List<int>(category => category.OrderNo, false);
			return View(categories);
		}

		[AcceptVerbs(HttpVerbs.Post)]
		public ActionResult Create(NewsCategory category)
		{
			BizNewsCategory.Insert(category);
			return RedirectToAction("List");
		}

		[AcceptVerbs(HttpVerbs.Post)]
		public ActionResult Edit(NewsCategory category)
		{
			BizNewsCategory.Update(category);
			return RedirectToAction("List");
		}

		[AcceptVerbs(HttpVerbs.Post)]
		public ActionResult Delete(int id)
		{
			BizNewsCategory.Delete(id);
			return RedirectToAction("List");
		}

	}
}
